import { NextResponse } from 'next/server';
import fs from 'fs';
import path from 'path';

export async function POST() {
  try {
    const dataDir = path.join(process.cwd(), 'data');
    
    // 清除JSON数据库文件
    const files = [
      'classifications.json',
      'attributes.json', 
      'entities.json',
      'parameter_mappings.json'
    ];
    
    files.forEach(file => {
      const filePath = path.join(dataDir, file);
      if (fs.existsSync(filePath)) {
        fs.unlinkSync(filePath);
      }
    });
    
    // 重新创建空文件
    if (!fs.existsSync(dataDir)) {
      fs.mkdirSync(dataDir, { recursive: true });
    }
    
    files.forEach(file => {
      fs.writeFileSync(path.join(dataDir, file), '[]');
    });
    
    return NextResponse.json({
      success: true,
      message: '数据库已清除'
    });
  } catch (error) {
    console.error('清除数据库失败:', error);
    return NextResponse.json(
      { error: '清除数据库失败' },
      { status: 500 }
    );
  }
} 